//
//  HomeSleepView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/20.
//

#import "HomeSleepView.h"
#import "HomeSleepInfoView.h"

@interface HomeSleepView()

@property (nonatomic,strong) UIView * lineView;
@property (nonatomic,strong) HomeSleepInfoView * allView;
@property (nonatomic,strong) HomeSleepInfoView * deepView;
@property (nonatomic,strong) HomeSleepInfoView * shallView;
@property (nonatomic,strong) HomeSleepInfoView * eyeView;
@property (nonatomic,strong) HomeSleepInfoView * awakeView;

@end

@implementation HomeSleepView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    [self addSubview:self.lineView];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake((WIDTH - 54 * FMScaleX), 18 * FMScaleX));
        make.centerX.equalTo(@0);
        make.top.mas_offset(3 * FMScaleX);
    }];
    [self addSubview:self.allView];
    [_allView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@0);
        make.left.mas_offset(27 * FMScaleX);
        make.size.mas_offset(CGSizeMake((WIDTH - 54 * FMScaleX) / 5, 50 * FMScaleX));
    }];
    [self addSubview: self.deepView];
    [_deepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.centerY.equalTo(self.allView);
        make.left.equalTo(self.allView.mas_right);
    }];
    [self addSubview:self.shallView];
    [_shallView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.centerY.equalTo(self.deepView);
        make.left.equalTo(self.deepView.mas_right);
    }];
    [self addSubview:self.eyeView];
    [_eyeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.centerY.equalTo(self.shallView);
        make.left.equalTo(self.shallView.mas_right);
    }];
    [self addSubview:self.awakeView];
    [_awakeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.centerY.equalTo(self.eyeView);
        make.left.equalTo(self.eyeView.mas_right);
    }];
}

-(void)setInfoModel:(HomeSleepModel *)infoModel{
    
    self.allView.timeLabel.text = [NSString stringWithFormat:@"%.1fh",minutesToHours(infoModel.allMinutes)];
    self.deepView.timeLabel.text = [NSString stringWithFormat:@"%.1fh",minutesToHours(infoModel.highTime)];
    self.eyeView.timeLabel.text = [NSString stringWithFormat:@"%.1fh",minutesToHours(infoModel.ydTime)];
    self.shallView.timeLabel.text = [NSString stringWithFormat:@"%.1fh",minutesToHours(infoModel.lowTime)];
    self.awakeView.timeLabel.text = [NSString stringWithFormat:@"%.1fh",minutesToHours(infoModel.qxTime)];
    
}

float minutesToHours(NSInteger minutes) {
    return (float)minutes / 60;
}


-(UIView *)lineView{
    
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        [_lineView setCornerRadius:7 * FMScaleX];
        _lineView.backgroundColor = RDRGB(0xEBE3DA);
    }
    return _lineView;
}
-(HomeSleepInfoView *)allView{
    
    if (!_allView) {
        _allView = [[HomeSleepInfoView alloc]init];
        _allView.infoLabel.text = @"总长";
    }
    return _allView;
}
-(HomeSleepInfoView *)deepView{
    
    if (!_deepView) {
        _deepView = [[HomeSleepInfoView alloc]init];
        _deepView.timeLabel.textColor = RDRGB(0xAD7D62);
        _deepView.infoLabel.text = @"深睡";
    }
    return _deepView;
}
-(HomeSleepInfoView *)eyeView{
    
    if (!_eyeView) {
        _eyeView = [[HomeSleepInfoView alloc]init];
        _eyeView.timeLabel.textColor = RDRGB(0xB6904A);
        _eyeView.infoLabel.text = @"眼动";
    }
    return _eyeView;
}
-(HomeSleepInfoView *)shallView{
    
    if (!_shallView) {
        _shallView = [[HomeSleepInfoView alloc]init];
        _shallView.timeLabel.textColor = RDRGB(0xEEB068);
        _shallView.infoLabel.text = @"浅睡";
    }
    return _shallView;
}
-(HomeSleepInfoView *)awakeView{
    
    if (!_awakeView) {
        _awakeView = [[HomeSleepInfoView alloc]init];
        _awakeView.timeLabel.textColor = RDRGB(0x7599E1);
        _awakeView.infoLabel.text = @"清醒";
    }
    return _awakeView;
}
@end
